/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ManagerAddProduct;

import java.sql.*;
import DBManager.DBConnection;
import java.util.Date;

/**
 *
 * @author Alex
 */
public class ManagerAddProduct {
     public boolean addProduct(Product newProduct)
    {
        boolean result = false;

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
            PreparedStatement pstmt =
                conn.prepareStatement("INSERT "
                    + "INTO products(mangid,title,synopsis,price,type)"
                    + " values(?,?,?,?,?)");

            //append values for the parameters
            int i=1;
             pstmt.setInt(i++, newProduct.getMangid());
        pstmt.setString(i++, newProduct.getTitle());
        pstmt.setString(i++, newProduct.getSynopsis());
        pstmt.setInt(i++, newProduct.getPrice());
        pstmt.setString(i++, newProduct.getType());
           
            //execute SQL statement
            pstmt.executeUpdate();

            result = true;
        }
        catch(SQLException ex){ex.printStackTrace();}

        return result;
    }
     
       public int Log(int x)
    { Date newDate = new java.util.Date();
       int result=0;
        
        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn =  db.getConnection();
             java.util.Date time = new java.util.Date();
             
            String query ="insert into logmanager(mangid,message) values(?,?)";
                   String message="Manager Added Product Date"+newDate;
                   String message1="\nManger Added Product:"+time;
          
            PreparedStatement pstmt =  conn.prepareStatement("insert into logmanager(mangid,message) values(?,?)");
            
            //append values for the parameters
            int i = 1;
            pstmt.setInt(i++, x);
            pstmt.setString(i++, message);
           
            pstmt.executeUpdate();
result=1;
            //execute SQL statement
         
          
        }
        catch(SQLException ex){ex.printStackTrace();}
        
        return result;
    }    
}
